//
//  LBCBTView.m
//  LifeEnjoy
//
//  Created by 刘表聪 on 15/9/10.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "LBCBTView.h"
#import "Masonry.h"
#import "UIButton+WebCache.h"

@implementation LBCBTView
#pragma mark - 初始化方法
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addAllViews];
        
    }
    return self;
}

#pragma mark - 添加所有控件
- (void)addAllViews
{
    // 设置button
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
//    [_button setImage:[UIImage imageNamed:@"placeholder.png"] forState:UIControlStateNormal];
    [_button setBackgroundImage:[UIImage imageNamed:@"placeholder.png"] forState:UIControlStateNormal];
    _button.frame = CGRectMake(self.frame.size.width * 0.1, 0, self.frame.size.width * 0.8, self.frame.size.width * 0.8);
    [self addSubview:_button];
    
    self.label = [[UILabel alloc] init];
    _label.font = [UIFont systemFontOfSize:10];
    _label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_label];
    __block typeof (self) weakSelf = self;
    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        if (self.size.height - _button.size.height > 20) {
            make.top.equalTo(weakSelf).with.offset(_button.frame.size.width + 5);
            _label.font = [UIFont systemFontOfSize:11];

        } else {
            
            make.top.equalTo(weakSelf).with.offset(_button.frame.size.width);
        }
        make.left.equalTo(weakSelf);
        make.right.equalTo(weakSelf);
    }];
    
    
}


#pragma mark - 赋值方法
- (void)setValuesWithImageUrlStr:(NSString *)urlStr
                           title:(NSString *)title
{
    [self.button sd_setBackgroundImageWithURL:[NSURL URLWithString:urlStr] forState:UIControlStateNormal];
    self.label.text = title;
}

@end
